package com.komodo.island.gdx.game.underwater;

import java.util.Random;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.komodo.island.gdx.AnimatedSprite;
import com.komodo.island.gdx.Constants;

public class Fish extends AnimatedSprite {

	// public final static int

	private Random rand;
	
	public int type;
	public String name;
	
	public int point;
	public int dir;

	/*
	 * TERI = 0 TONGKOL = 1 LELE = 2
	 */

	private static final int[] fishX = { (int) (Gdx.graphics.getWidth() * 0.1),
			(int) (Gdx.graphics.getWidth() * 0.1) + 100,
			(int) (Gdx.graphics.getWidth() * 0.1) + 200 ,
			(int) (Gdx.graphics.getWidth() * 0.1) + 300 ,
			(int) (Gdx.graphics.getWidth() * 0.1) + 400 };
	
	private static final int[] fishY = { (int) (Gdx.graphics.getWidth() * 0.1),
			(int) (Gdx.graphics.getWidth() * 0.1),
			(int) (Gdx.graphics.getWidth() * 0.1) ,
			(int) (Gdx.graphics.getWidth() * 0.1) + 200
			,(int) (Gdx.graphics.getWidth() * 0.1) + 300 };
	
	private static final String[] fishName = { "ikan kuning", "ikan lupa", "ikan aneh", "ikan badut","ikan ungu","dolphin",
		
		
	"bintang laut", "ephippidea","gurita","pari","dugong","baracudda"};
	
	private static final int[] fishPoint = { 100,125,120,130,110,200,115,125,175,225,230,315};
//	private static final float[] fishPeriod = { 1, (float) 0.5, (float) 0.25 }; // fish
																				// swimming
																				// period.
																				// less
																				// ->
																				// faster
	public static final int BARACUDDA = 11;
	public static final int DUGONG = 10;
	public static final int PARI = 9;
	public static final int GURITA = 8;
	public static final int EPHIPPIDEA = 7;
	public static final int BINTANG = 6;
	public static final int DOLPHIN = 5;
	public static final int IKANUNGU = 4;
	public static final int IKANBADUT = 3;
	public static final int IKANANEH = 2;
	public static final int IKANLUPA = 1;
	public static final int IKANKUNING = 0;
	
	
	

	public Fish(TextureRegion []frames,int fishType, int x, int y, int dir, Random random) {
		super(frames);
		type = fishType;
		name = fishName[fishType];
		
		setPosition(x, y);
		this.dir = dir;
		point = fishPoint[fishType];
		this.rand  = random;
	}

	private void moveRight() {
		int step = 3 ;
		
		if (type == 3){
			step = 5;
		}else if (type == 4){
			step = 20;
		}
		
		if (type > 0)
			step += rand.nextInt(2) * 5 +rand.nextInt(type);
		
		setPosition(getX() + step, getY());
		
	}

	private void moveLeft() {
		int step = 3 ;
		
		if (type == 3){
			step = 5;
		}else if (type == 4){
			step = 20;
		}
		
		if (type > 0)
			step += rand.nextInt(2) * 5 +rand.nextInt(type);
		
		setPosition(getX() - step, getY());
	}

	public void checkFlip() {
		if (getX() + getWidth()< 0){
			dir = 1;	
			setPosition(getX(), rand.nextInt(Gdx.graphics.getHeight()));
		}
		if (getX() > (480 * 3) ){
			dir = -1;
			setPosition(getX(), rand.nextInt(Gdx.graphics.getHeight()));
		}
			
	}

	
	public void move(float stateTime) {
			if (dir==1) {
				setScale(1,1);
				nextKey(stateTime);		
				moveRight();
			} else if (dir == -1) {
				setScale(-1,1);
				nextKey(stateTime);		
				moveLeft();
			}
		

	}
	
	public void move(double t) {
		// System.out.println("haai"+t);
//		if (t - Math.round(t) <= 0.01 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.02 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.03 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.04) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.05 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.06 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.07 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.08 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}else if (t - Math.round(t) <= 0.09 ) {
//			if (dir == 1)// right
//				moveRight();
//			if (dir == -1)// left
//				moveLeft();
//		}
//		
		if (dir == 1)// right
			moveRight();
		if (dir == -1)// left
			moveLeft();
//		else if (((int) t *12) % (2 * (3 - type) + 2) == 0){
//			flip();
//		}
	
	}
	
	
	
	
	public void flip(){
		dir =  dir * -1;
	}

}